package org.jwos.plugin.file.domain;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.jwos.plugin.file.util.MapUtil;


public class FolderInfo extends MappableBean implements Serializable {
	
	private String id;
	
	private String text;
	
	private int type;
	
	private boolean shared = false;
	
	private String iconCls;
	
	private boolean allowDrag = true;
	
	private boolean allowDrop = true;
	
	private boolean expanded = false;
	
	private String parentFolderId = "";
	
	private List children = null;	 

	public FolderInfo() {
		this(FolderType.FileFolder);
	}
	
	public FolderInfo(int type) {
		this.setType(type);
	}
	
	public Map toMap() {
		Map map = super.toMap();
		
		if(children!=null && children.size()>0) {
			map.remove("children");
			List list = MapUtil.beanListToMapList(children);
			map.put("children", list);
		}
		
		return map;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
		this.setIconCls(FolderType.getIconClassByFolderType(type,shared));
		this.setAllowDrag(FolderType.getAllowDragByFolderType(type));
		this.setAllowDrop(FolderType.getAllowDropByFolderType(type));				
	}

	public String getIconCls() {
		return iconCls;
	}

	public void setIconCls(String iconCls) {
		this.iconCls = iconCls;
	}

	public boolean isAllowDrag() {
		return allowDrag;
	}

	public void setAllowDrag(boolean allowDrag) {
		this.allowDrag = allowDrag;
	}

	public boolean isAllowDrop() {
		return allowDrop;
	}

	public void setAllowDrop(boolean allowDrop) {
		this.allowDrop = allowDrop;
	}

	public boolean isExpanded() {
		if(type==FolderType.PublishedFiles || type==FolderType.PublishedFolders) {
			this.setExpanded(true);
		}
		return expanded;
	}

	public void setExpanded(boolean expanded) {
		this.expanded = expanded;
	}

	public List getChildren() {
		return children;
	}

	public void setChildren(List children) {
		this.children = children;
	}

	public boolean isShared() {
		return shared;
	}

	public void setShared(boolean shared) {
		this.shared = shared;
		this.setIconCls(FolderType.getIconClassByFolderType(type,shared));
	}

	public String getParentFolderId() {
		return parentFolderId;
	}

	public void setParentFolderId(String parentFolderId) {
		this.parentFolderId = parentFolderId;
	}
}
